package com.zy.mc_module.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ScrollView;

import com.zy.mc_module.utils.ScreenUtils;


/**
 * author : dq
 * date   : 19/6/27
 * desc   : ScrollView 嵌套 TextView，限制TextView最大高度
 */
public class MaxHeightScrollView extends ScrollView {

    private int maxHeight;

    public MaxHeightScrollView(Context context) {
        this(context, null);
    }

    public MaxHeightScrollView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MaxHeightScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        maxHeight = (int) (ScreenUtils.getScreenHeight(context) * 0.5f);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(maxHeight, MeasureSpec.AT_MOST));
    }
}
